package bookshopSM;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

import javax.swing.*;

import book.AddBook;
import book.BookInstock;
import book.DeleteBook;
import book.SelectBook;
import book.UpdateBook;

import sale.Bestseller;
import sale.ViewSaleList;
import sale.ViewSaleMoney;
import worker.AddWorker;
import worker.DeleteWorker;
import worker.ResetWorkerCode;
import worker.UpdateWorker;

import VIP.AddVIP;
import VIP.DeleteVIP;
import VIP.UpdateVIP;
import VIP.VIPSet;

public class FrameAdmin extends JFrame implements ActionListener{

    JMenuBar jMenuBar1 = new JMenuBar();
    JMenu jMenu1 = new JMenu("销售管理");
    JMenuItem jMenuItem11 = new JMenuItem("查看销售列表");
    JMenuItem jMenuItem12 = new JMenuItem("查看销售额");
    JMenuItem jMenuItem13 = new JMenuItem("查看畅销书单");
    JMenu jMenu2 = new JMenu("图书管理");
    JMenuItem jMenuItem21 = new JMenuItem("图书入库");
    JMenuItem jMenuItem22 = new JMenuItem("添加新图书");
    JMenuItem jMenuItem23 = new JMenuItem("修改图书信息");
    JMenuItem jMenuItem24 = new JMenuItem("删除图书信息");
    JMenuItem jMenuItem25 = new JMenuItem("图书查询");
    JMenu jMenu3 = new JMenu("员工管理");
    JMenuItem jMenuItem31 = new JMenuItem("添加新员工");
    JMenuItem jMenuItem32 = new JMenuItem("修改员工信息");
    JMenuItem jMenuItem33 = new JMenuItem("删除员工信息");
    JMenuItem jMenuItem34 = new JMenuItem("重置员工密码");
    JMenu jMenu4 = new JMenu("会员管理");
    JMenuItem jMenuItem41 = new JMenuItem("会员设置");
    JMenuItem jMenuItem42 = new JMenuItem("添加新会员");
    JMenuItem jMenuItem43 = new JMenuItem("修改会员信息");
    JMenuItem jMenuItem44 = new JMenuItem("删除会员信息");
    public FrameAdmin()
    {	    String path = "bgp.jpg";
        // 背景图片
        ImageIcon background = new ImageIcon(path);
        // 把背景图片显示在一个标签里面
        JLabel label = new JLabel(background);
        // 把标签的大小位置设置为图片刚好填充整个面板
        label.setBounds(0, 0, this.getWidth(), this.getHeight());
        // 把内容窗格转化为JPanel，否则不能用方法setOpaque()来使内容窗格透明
        JPanel imagePanel = (JPanel) this.getContentPane();
        imagePanel.setOpaque(false);
        // 把背景图片添加到分层窗格的最底层作为背景
        this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
        //创建组件
        this.setSize(900, 700);
        // 获取屏幕尺寸
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        //获取主界面的窗体尺寸
        Dimension frameSize = this.getSize();
        this.setLocation((screenSize.width - frameSize.width) /2,
                (screenSize.height - frameSize.height) / 2);//居中显示

        JPanel contentPane = (JPanel) getContentPane();
        contentPane.setLayout( new BorderLayout() );
        setTitle("书店销售管理系统");
        setJMenuBar(jMenuBar1);
        jMenuBar1.add(jMenu1);
        jMenuBar1.add(jMenu2);
        jMenuBar1.add(jMenu3);
        jMenuBar1.add(jMenu4);
        jMenu1.add(jMenuItem11);
        jMenu1.add(jMenuItem12);
        jMenu1.add(jMenuItem13);
        jMenu2.add(jMenuItem21);
        jMenu2.add(jMenuItem22);
        jMenu2.add(jMenuItem23);
        jMenu2.add(jMenuItem24);
        jMenu2.add(jMenuItem25);
        jMenu3.add(jMenuItem31);
        jMenu3.add(jMenuItem32);
        jMenu3.add(jMenuItem33);
        jMenu3.add(jMenuItem34);
        jMenu4.add(jMenuItem41);
        jMenu4.add(jMenuItem42);
        jMenu4.add(jMenuItem43);
        jMenu4.add(jMenuItem44);

        jMenuItem11.addActionListener(this);
        jMenuItem12.addActionListener(this);
        jMenuItem13.addActionListener(this);
        jMenuItem21.addActionListener(this);
        jMenuItem22.addActionListener(this);
        jMenuItem23.addActionListener(this);
        jMenuItem24.addActionListener(this);
        jMenuItem25.addActionListener(this);
        jMenuItem31.addActionListener(this);
        jMenuItem32.addActionListener(this);
        jMenuItem33.addActionListener(this);
        jMenuItem34.addActionListener(this);
        jMenuItem41.addActionListener(this);
        jMenuItem42.addActionListener(this);
        jMenuItem43.addActionListener(this);
        jMenuItem44.addActionListener(this);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
    }
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        //查看销售列表 查看销售额 添加新图书 图书入库 添加新员工 修改员工信息 删除员工信息
        //会员设置 添加新会员 修改会员信息 删除会员信息
        //查看销售列表
        if (e.getSource() == jMenuItem11)
        {  // 创建添加学生面板对象
            ViewSaleList VSL = new ViewSaleList();
            // 移除主界面上原有的内容
            this.remove(this.getContentPane());
            // 令界面可见
            this.setContentPane(VSL);
            this.setVisible(true);
        }


        //查看销售额
        if (e.getSource() == jMenuItem12){
            ViewSaleMoney VSM = new ViewSaleMoney();
            this.remove(this.getContentPane());
            this.setContentPane(VSM);
            this.setVisible(true);
        }
        //查看畅销书单
        if (e.getSource() == jMenuItem13){
            Bestseller VSM = new Bestseller();
            this.remove(this.getContentPane());
            this.setContentPane(VSM);
            this.setVisible(true);
        }
        //图书入库
        if (e.getSource() == jMenuItem21){
            BookInstock BI = new BookInstock();
            this.remove(this.getContentPane());
            this.setContentPane(BI);
            this.setVisible(true);
        }
        //添加新图书
        if (e.getSource() == jMenuItem22){
            AddBook AB = new AddBook();
            this.remove(this.getContentPane());
            this.setContentPane(AB);
            this.setVisible(true);
        }
        //修改图书信息
        if (e.getSource() == jMenuItem23){
            UpdateBook AB = null;
            try {
                AB = new UpdateBook();
            } catch (SQLException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            this.remove(this.getContentPane());
            this.setContentPane(AB);
            this.setVisible(true);
        }
        //删除图书信息
        if (e.getSource() == jMenuItem24){
            DeleteBook AB = null;
            try {
                AB = new DeleteBook();
            } catch (SQLException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            this.remove(this.getContentPane());
            this.setContentPane(AB);
            this.setVisible(true);
        }
        //图书查询
        if (e.getSource() == jMenuItem25){
            SelectBook AB = null;
            AB = new SelectBook();
            this.remove(this.getContentPane());
            this.setContentPane(AB);
            this.setVisible(true);
        }
        //添加新员工
        if (e.getSource() == jMenuItem31){
            AddWorker AW = new AddWorker();
            this.remove(this.getContentPane());
            this.setContentPane(AW);
            this.setVisible(true);
        }
        //修改员工信息
        if (e.getSource() == jMenuItem32){
            UpdateWorker UW = new UpdateWorker();
            this.remove(this.getContentPane());
            this.setContentPane(UW);
            this.setVisible(true);
        }
        //删除员工信息
        if (e.getSource() == jMenuItem33){
            DeleteWorker VS = new DeleteWorker();
            this.remove(this.getContentPane());
            this.setContentPane(VS);
            this.setVisible(true);
        }
        //重置员工密码
        if (e.getSource() == jMenuItem34){
            ResetWorkerCode VS = null;
            try {
                VS = new ResetWorkerCode();
            } catch (SQLException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            this.remove(this.getContentPane());
            this.setContentPane(VS);
            this.setVisible(true);
        }
        //会员设置
        if (e.getSource() == jMenuItem41){
            VIPSet VS = null;
            try {
                VS = new VIPSet();
            } catch (SQLException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            this.remove(this.getContentPane());
            this.setContentPane(VS);
            this.setVisible(true);
        }
        //添加新会员
        if (e.getSource() == jMenuItem42){
            AddVIP VS = new AddVIP();
            this.remove(this.getContentPane());
            this.setContentPane(VS);
            this.setVisible(true);
        }
        //修改会员信息
        if (e.getSource() == jMenuItem43){
            UpdateVIP VS = null;
            try {
                VS = new UpdateVIP();
            } catch (SQLException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            this.remove(this.getContentPane());
            this.setContentPane(VS);
            this.setVisible(true);
        }
        //删除会员信息
        if (e.getSource() == jMenuItem44){
            DeleteVIP VS = null;
            try {
                VS = new DeleteVIP();
            } catch (SQLException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            this.remove(this.getContentPane());
            this.setContentPane(VS);
            this.setVisible(true);
        }
    }

}

